using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using LS.UnityExtensions.Editor;
using LS.GameKit.SequenceAnimate;

namespace LS.GameKit.Editor
{
    [CustomEditor(typeof(SequenceAnimation))]
    public class SequenceAnimationInspector : InspectorBase
    {
        protected SerializedProperty m_PlayOnEnable;
        protected SerializedProperty m_UpdateWithoutTimeScale;
        protected SerializedProperty m_SequenceRendererType;
        protected SerializedProperty m_SpriteRenderer;
        protected SerializedProperty m_MeshRenderer;
        protected SerializedProperty m_SkinnedMeshRenderer;
        protected SerializedProperty m_Image;
        protected SerializedProperty m_ElementName;
        protected SerializedProperty m_UiDocument;
        protected SerializedProperty m_Material;
        protected SerializedProperty m_Clips;
        protected SerializedProperty m_OnStartPlay;
        protected SerializedProperty m_OnEndPlay;
        
        protected override void OnEnable()
        {
            base.OnEnable();
            m_PlayOnEnable = FindProperty("m_PlayOnEnable");
            m_UpdateWithoutTimeScale = FindProperty("m_UpdateWithoutTimeScale");
            m_SequenceRendererType = FindProperty("m_SequenceRendererType");
            m_SpriteRenderer = FindProperty("m_SpriteRenderer");
            m_MeshRenderer = FindProperty("m_MeshRenderer");
            m_SkinnedMeshRenderer = FindProperty("m_SkinnedMeshRenderer");
            m_Image = FindProperty("m_Image");
            m_ElementName = FindProperty("m_ElementName");
            m_UiDocument = FindProperty("m_UiDocument");
            m_Clips = FindProperty("m_Clips");
            m_OnStartPlay = FindProperty("OnStartPlay");
            m_OnEndPlay = FindProperty("OnEndPlay");
            m_Material = FindProperty("m_Material");
        }

        public override void DrawInspectorItems()
        {
            base.DrawInspectorItems();
            EditorGUILayout.PropertyField(m_PlayOnEnable);
            EditorGUILayout.PropertyField(m_UpdateWithoutTimeScale);
            EditorGUILayout.PropertyField(m_SequenceRendererType);

            SequenceRendererType rendererType = (target as SequenceAnimation).SequenceRendererType;

            if(rendererType == SequenceRendererType.SpriteRenderer)
            {
                EditorGUILayout.PropertyField(m_SpriteRenderer);
            }
            else if (rendererType == SequenceRendererType.SkinnedMeshRenderer)
            {
                EditorGUILayout.PropertyField(m_SkinnedMeshRenderer);
            }
            else if (rendererType == SequenceRendererType.MeshRenderer)
            {
                EditorGUILayout.PropertyField(m_MeshRenderer);
            }
            else if (rendererType == SequenceRendererType.MeshRenderer)
            {
                EditorGUILayout.PropertyField(m_MeshRenderer);
            }
            else if (rendererType == SequenceRendererType.UIElement)
            {
                EditorGUILayout.PropertyField(m_ElementName);
                EditorGUILayout.PropertyField(m_UiDocument);
            }
            else if (rendererType == SequenceRendererType.Material)
            {
                EditorGUILayout.PropertyField(m_Material);
            }
            else if (rendererType == SequenceRendererType.UGuiImage)
            {
                EditorGUILayout.PropertyField(m_Image);
            }

            EditorGUILayout.PropertyField(m_Clips);
            EditorGUILayout.PropertyField(m_OnStartPlay);
            EditorGUILayout.PropertyField(m_OnEndPlay);
        }
    }
}
